/**
 * Created by Administrator on 2018/4/28.
 */
/**
 * Created by Administrator on 2018/4/26.
 */
define(function (require,exports,module) {
    var sTpl = require("./template.html");
    require("./examine.css");
    require("../../../lib/fullcalendar/moment.min.js");

    var enter = require("../enter/enter.js");
    var VueComponent = Vue.extend({
        template: sTpl,
        components:{
            'enters':enter
        }
        ,methods:{
            queryAppointment :function(){
                var  exceptDateS = this.form.startDate?this.form.startDate[0]:"";
                var  exceptDateE = this.form.startDate?this.form.startDate[1]:"";
                // var status =(this.form.appoCancle?"预约取消,":"")+(this.form.examinePass?"审核通过,":"")+(this.form.examineCancle?"审核取消,":"")+(this.form.unExamine?"未审核,":"");
                this.urls.url=this.urls.initurl+"&appoUnit="+this.form.appoUnit+"&appoPhoneNum="+this.form.appoPhoneNum+
                    "&startDate="+exceptDateS+"&endDate="+exceptDateE;
                if(this.$refs.flightPlane){
                    this.$refs.flightPlane.resetFields();
                }
            },
            onSubmit:function() {
                console.log('submit!');
            },
            querySearchUnit:function(queryString, cb) {
                var restaurants = this.units;
                console.log(this.form);
                var results = queryString ? restaurants.filter(function(restaurant){
                    return (restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
                }) : restaurants;
                // 调用 callback 返回建议列表的数据
                cb(results);
            },pickTime:function (val) {
                this.formData.appoDate = val;
            },
            editAppointment:function(scope){
                var $this= this;
                this.$refs.enters.formData=JSON.parse(JSON.stringify(scope.row)) ;

                this.$refs.enters.formData.agreement=this.$refs.enters.formData.agreement?this.$refs.enters.formData.agreement:{contractManageId:""}
                this.$refs.enters.contractChange(this.$refs.enters.formData.agreement.contractManageId);
                this.$refs.enters.parentData.showOrEdit='edit';
                this.$refs.enters.parentData.dataCallBack=function(data){
                    scope.row=data;
                }
                $("#panel-activer").click();
            },
            examineAppointment:function(scope){
                this.$refs.enters.formData=scope.row;
                this.$refs.enters.formData.agreement=this.$refs.enters.formData.agreement?this.$refs.enters.formData.agreement:{contractManageId:""}
                this.$refs.enters.contractChange(this.$refs.enters.formData.agreement.contractManageId);
                this.$refs.enters.parentData.showOrEdit='show';
                this.$refs.enters.parentData.dataCallBack=function(data){
                    $this.$set( $this.$refs.table.$refs.elTable.data,scope.$index,data)
                }
                $("#panel-activer").click();
            },
            transformToFlightPlane:function(scope){
                var $this = this ;
                this.$confirm('确定要转换为航班计划？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'success'
                }).then(function() {
                    axios.post(basepath+'/api/appointment/transFormToFlightPlane',scope.row)
                        .then(function (response) {


                            // scope.row=response.data;
                            $this.$set($this.$refs.table.internalData,scope.$index,response.data)

                            $this.$notify({
                                title: '转换成功',
                                message: '已转换为航班计划'
                            });
                        });
                });
            },

            passAppointment:function(scope,status){
                var $this = this ;
                this.$confirm('确定'+status+'？', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'success'
                }).then(function() {
                    scope.row.status=status;
                    axios.post(basepath+'/api/appointment/passAppointment',scope.row)
                        .then(function (response) {
                            scope.row=response.data;
                            $this.$notify({
                                title: "操作成功",
                                message: '该预约已取消！'
                            });
                        });
                })
            }

        },

        mounted:function() {

        }
        ,data:function(){
            return {
                form: {
                    appoUnit: '',
                    startDate:"",
                    endDate:'',
                    unExamine:true,
                    appoCancle:false,
                    examinePass:true,
                    examineCancle:true,
                    appoPhoneNum:'',
                    type:""
                },
                pickerOptions2: {
                    shortcuts: [{
                        text: '最近一周',
                        onClick:function(picker) {
                            const end = moment().format("YYYY-MM-DD");
                            const start = moment(new Date().getTime() + 3600 * 1000 * 24 * 7).format("YYYY-MM-DD");
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近一个月',
                        onClick:function(picker) {
                            const end = moment().format("YYYY-MM-DD");
                            const start = moment(new Date().getTime() + 3600 * 1000 * 24 * 30).format("YYYY-MM-DD");
                            picker.$emit('pick', [start, end]);
                        }
                    }, {
                        text: '最近三个月',
                        onClick:function(picker) {
                            const end = moment().format("YYYY-MM-DD");
                            const start = moment(new Date().getTime() + 3600 * 1000 * 24 * 90).format("YYYY-MM-DD");
                            picker.$emit('pick', [start, end]);
                        }
                    }]
                },
                parentData:{
                    showOrEdit:"show",
                    returnParent:function(){
                        $("#panel-activer").click();
                    }
                }
                ,
                units: [{value:"诺基亚"},{value:"经信委"},{value:"浑水江"}],
                urls:{
                    url:basepath+"/api/appointment/getAppointments?sort=appoId",
                    initurl:basepath+"/api/appointment/getAppointments?sort=appoId",
                },
                formData: []
            }
        },
        created:function (){
            this.queryAppointment();

           // this.urls.url = basepath+"api/appointment/findAppointment";
        },
        activated:function () {
            messages.$emit('change','预约信息管理');
        }

    });
    module.exports = VueComponent;
})
